package com.phkj.routing;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Send {
  private final static String EXCHANGE_NAME = "routing-example";

  public static void main(String[] argv)throws Exception {
      ConnectionFactory factory = new ConnectionFactory();
      factory.setHost("localhost");
      Connection connection = factory.newConnection();
      // 从连接中创建通道
      Channel channel = connection.createChannel();
      // 声明exchange
      channel.exchangeDeclare(EXCHANGE_NAME, "direct");
      // 消息内容
      String message = "Hello World!";
      channel.basicPublish(EXCHANGE_NAME, "key2", null,message.getBytes());
      System.out.println(" 后端系统发送信息 '" + message + "'");
      //关闭通道和连接
      channel.close();
      connection.close();
  }
}  